package com.neuronrobotics.replicator.gui.stl;

import java.util.Arrays;

import javax.vecmath.Matrix4f;


public class DefaultGeneralTransform3D implements GeneralTransform3D{

	private Matrix4f theMatrix;	
	
	public DefaultGeneralTransform3D(){
		theMatrix = new Matrix4f(new float[]{1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1});
	}
	
	public DefaultGeneralTransform3D(float[] tran, MatrixOrder matOrder){
		float temp[] = Arrays.copyOf(tran, 16);
		if(matOrder==MatrixOrder.COLUMN_MAJOR){
			MatrixOrder.convertOrder(temp, 0, temp, 0);
		}
		theMatrix = new Matrix4f(temp);
	}
	
	public DefaultGeneralTransform3D(Matrix4f tran){
		theMatrix = new Matrix4f(tran);
	}
	
	@Override
	public void get(float[] transform,MatrixOrder mo) {
		
		for(int i=0;i<16;i++) transform[i]=theMatrix.getElement(i/4, i%4);
		if(mo==MatrixOrder.COLUMN_MAJOR) MatrixOrder.convertOrder(transform, 0,transform, 0);
		
	}

	//TODO test
	@Override
	public void set(float[] newTransform, MatrixOrder mo) {
		
		float[] temp = Arrays.copyOf(newTransform, 0);
		if(mo==MatrixOrder.COLUMN_MAJOR) MatrixOrder.convertOrder(temp, 0, temp, 0);
				
		theMatrix.set(temp);		
		
	}

}
